<?php
    class Home_Controller extends DL_Controller
    {
	public function index()
	{
	    echo $this->lang->line('hello world')." controllers/home_controller.php method:home ";
	    //print_r($_GET);
	    //$this->load('helper','xxx');
	    xxx('sdfsdfds');
	}
	
	public function test_route(){
	    echo "This is test route";
	}
	
	public function test_route_any($var){
	    echo "This is test route (:any) => {$var}";
	}
	
	public function test_route_num($var){
	    echo "This is test route (:num) => $var";
	}
    
	
	public function test_route_any_profile($var){
	    echo "This is test route (:any/profile) => {$var}";
	}
	
	public function test_route_num_profile($var){
	    echo "This is test route (:num/profile) => $var";
	}
	
	public function test_route_reg($var){
	    echo "This is test route regular expression => $var";
	}
	
	public function test_route_reg_123(){
	    echo "This is test route regular expression => test_route_reg_123()";
	}
	
	public function test_model(){
	    $this->load('model','home_model','home_model');
	    $this->home_model->test_model();
	}
	
	public function test_zend_db(){
	    $this->load('library','zend');
	    $this->zend->load('zend/db');
	    $this->zend->db->factory('Pdo_Mysql',array(
		'host'     => 'localhost',
		'username' => 'root',
		'password' => '1234',
		'dbname'   => 'mypro_all_fw'
	    ));
	    
	    $sql = 'SELECT * FROM users WHERE id  = ?';
	    $result = $this->zend->db->fetchAll($sql, 1);
	}
	
	public function test_view(){
	    $this->load('view','home_view');
	    
	    $this->view->set_var("Name","Fred Irving Johnathan Bradley Peppergill",true);
	    $this->view->set_var("FirstName",array("John","Mary","James","Henry"));
	    $this->view->set_var("LastName",array("Doe","Smith","Johnson","Case"));
	    $this->view->set_var("Class",array(array("A","B","C","D"), array("E", "F", "G", "H"),
		array("I", "J", "K", "L"), array("M", "N", "O", "P")));
	    
	    $this->view->set_var("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
		array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
	    
	    $this->view->set_var("option_values", array("NY","NE","KS","IA","OK","TX"));
	    $this->view->set_var("option_output", array("New York","Nebraska","Kansas","Iowa","Oklahoma","Texas"));
	    $this->view->set_var("option_selected", "NE");
	    
	    $this->view->display();
	}
	
	public function test_tpleng(){
	    $this->load('view','tpleng_view.html');
	    $person= array(
		'name' => 'Bart',
		'surname' => 'Simpson',
		'passports' => array(
			    'code' => '666',
			    'serialno' => '999'));
	    
	    $this->view->set_var('persons', $person);
	    $this->view->display();
	}
	
	public function test_raintpl(){
	    $this->load('view','tpleng_view.html');
	    $person= array(
		'name' => 'Bart',
		'surname' => 'Simpson',
		'passports' => array( 'code' => '666' , 'serialno' => '999')
	    );
	    //$this->view->clear_cache();
	    $this->view->set_cache(1);
	    $this->view->set_var('persons', $person);
	    $this->view->display();
	    //$html = $this->view->html();
	    //echo $html;
	}
	
	public function test_raintpl_ex1(){
	    $this->load('view','raintpl2/page.html');
	    
	    global $global_variable;
	    $global_variable = "I'm Global";
    
	    // set variables
	    $var = array(
		"variable"	=> "Hello",
		"version"	=> "3.0 Alpha",
		"menu"	=> array( 
				    array("name" => "Home", "link" => "index.php", "selected" => true ),
				    array("name" => "FAQ", "link" => "index.php/FAQ/", "selected" => null ),
				    array("name" => "Documentation", "link" => "index.php/doc/", "selected" => null )
				),
		"week"	=> array( "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ),
		"title"	=> "Rain TPL 3 - Easy and Fast template engine", 
		"user"	=> array( 
					array("name" => "Fede", "color" => "blue" ),
					array("name" => "Sheska", "color" => "red" ),
					array("name" => "Who", "color" => "yellow" ),
				    ),
		"empty_array" => array(), 
		"copyright" => "Copyright 2006 - 2012 Rain TPL<br>Project By Rain Team",
	    );
	    
	    $test = function( $params ){
		    $value = $params[0];
		    return "Translate: <b>$value</b>";
	    };
	    // add a function
	    $this->view->register_tag( "({@.*?@})", "{@(.*?)@}", $test );
	    
	    $this->view->set_cache();
	    $this->view->set_var('persons', $var);
	    $this->view->display();
	}
	
	public function test_raintpl_master(){
	    $this->load('view','master/header.html');
	    $this->view->set_var('title', 'test master template');
	    $header = $this->view->html();
	    
	    $this->load('view','master/footer.html');
	    $this->view->set_var('copyright', "Copyright 2006 - 2012 Rain TPL<br>Project By Rain Team");
	    $footer = $this->view->html();
	    
	    $this->load('view','test_master.html');
	    
	    global $global_variable;
	    $global_variable = "I'm Global";
    
	    // set variables
	    $var = array(
		"variable"	=> "Hello",
		"version"	=> "3.0 Alpha",
		"menu"	=> array( 
				    array("name" => "Home", "link" => "index.php", "selected" => true ),
				    array("name" => "FAQ", "link" => "index.php/FAQ/", "selected" => null ),
				    array("name" => "Documentation", "link" => "index.php/doc/", "selected" => null )
				),
		"week"	=> array( "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ),
		"title"	=> "Rain TPL 3 - Easy and Fast template engine", 
		"user"	=> array( 
					array("name" => "Fede", "color" => "blue" ),
					array("name" => "Sheska", "color" => "red" ),
					array("name" => "Who", "color" => "yellow" ),
				    ),
		"empty_array" => array(), 
		"copyright" => "Copyright 2006 - 2012 Rain TPL<br>Project By Rain Team",
	    );
	    
	    $test = function( $params ){
		    $value = $params[0];
		    return "Translate: <b>$value</b>";
	    };
	    // add a function
	    $this->view->register_tag( "({@.*?@})", "{@(.*?)@}", $test );
	    
	    //$this->view->set_cache();
	    $this->view->set_var('persons', $var);
	    $this->view->set_var('header', $header);
	    $this->view->set_var('footer', $footer);
	    $this->view->display();
	}
    }